package com;

import com.pojo.User;
import com.service.UserService;

@Configuration // 说明当前类是配置类 作用类似applicationContext.xml
@ComponentScan // 扫描项目中的所有bean类（添加了@Component
public class AppConfig {
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        HelloSpring helloSpring = context.getBean(HelloSpring.class);
        helloSpring.setUserName("小明");
        helloSpring.show();
        User user = context.getBean(User.class);
        // 上下两行作用等同于User user= new User();
        System.out.println(user);
        UserService userService = context.getBean(UserService.class);
        boolean flag = userService.login("张三","123");
        if (flag){
            System.out.println("登录成功");
        }else {
            System.out.println("登录失败");
        }
    }
}
